﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Reflection;
using MSWord = Microsoft.Office.Interop.Word;
//using Excel = Microsoft.Office.Interop.Excel;
using Microsoft.Office.Interop.Word;
using System.Windows.Forms;
using Microsoft.Office.Core;
using System.Data.SqlClient;
using System.Data;
using DBUtility;

namespace 一键生成
{
    class CreateWord1
    {
        int k = 1;
        object path;//文件路径
        string strContent;//文件内容
        MSWord.Application wordApp;//Word应用程序变量
        MSWord.Document wordDoc;//Word文档变量
        string str = "Data Source=192.168.1.214;Initial Catalog=HSXH;Persist Security Info=True;User ID=sa;Password=Ningtu2015";

        #region  准备资料
        //创建word
        public void CreateWord()
        {
            MSWord.Application wordApp; //Word应用程序变量
            MSWord.Document wordDoc; //Word文档变量
            object path;//文件路径
            string strContent;//文件内容
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档

            wordApp = new MSWord.ApplicationClass();//初始化
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
            //由于使用的是COM 库，因此有许多变量需要用Missing.Value 代替
            Object Nothing = Missing.Value;
            //新建一个word对象
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            //WdSaveDocument为Word2003文档的保存格式(文档后缀.doc)\wdFormatDocumentDefault为Word2007的保存格式(文档后缀.docx)
            object format = MSWord.WdSaveFormat.wdFormatDocument;
            //将wordDoc 文档对象的内容保存为DOC 文档,并保存到path指定的路径
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            //关闭wordDoc文档
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            //关闭wordApp组件对象
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            //Response.Write("<script>alert('" + path + ": Word文档创建完毕!');</script>");
            MessageBox.Show("操作完成");
        }

        //创建Word文档格式
        public void SetWordStyle()
        {
            object path;//文件路径
            string strContent;//文件内容
            MSWord.Application wordApp;//Word应用程序变量
            MSWord.Document wordDoc;//Word文档变量
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档
            wordApp = new MSWord.ApplicationClass();//初始化
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
            Object Nothing = Missing.Value;
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            //页面设置
            wordDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;//设置纸张样式
            wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;//排列方式为垂直方向
            wordDoc.PageSetup.TopMargin = 57.0f;
            wordDoc.PageSetup.BottomMargin = 57.0f;
            wordDoc.PageSetup.LeftMargin = 57.0f;
            wordDoc.PageSetup.RightMargin = 57.0f;
            wordDoc.PageSetup.HeaderDistance = 30.0f;//页眉位置

            //设置页眉
            wordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;//视图样式
            wordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;//进入页眉设置，其中页眉边距在页面设置中已完成
            wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;

            //插入页眉图片(测试结果图片未插入成功)(Paragraph段落格式Format格式Alignment对齐)
            wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
            string headerfile = "d:\\1.jpg";
            Microsoft.Office.Interop.Word.InlineShape shape1 = wordApp.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(headerfile, ref Nothing, ref Nothing, ref Nothing);
            shape1.Height = 20;
            shape1.Width = 80;
            wordApp.ActiveWindow.ActivePane.Selection.InsertAfter("2015年观测资料汇编                    滨海抽水站");
            //去掉页眉的横线
            wordApp.ActiveWindow.ActivePane.Selection.ParagraphFormat.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            wordApp.ActiveWindow.ActivePane.Selection.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].Visible = false;
            wordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//退出页眉设置

            //为当前页添加页码
            Microsoft.Office.Interop.Word.PageNumbers pns = wordApp.Selection.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers;//获取当前页的号码
            pns.NumberStyle = Microsoft.Office.Interop.Word.WdPageNumberStyle.wdPageNumberStyleNumberInDash;
            pns.HeadingLevelForChapter = 0;
            pns.IncludeChapterNumber = false;
            pns.RestartNumberingAtSection = false;
            pns.StartingNumber = 0;
            object pagenmbetal = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;//将号码设置在中间
            object first = true;
            wordApp.Selection.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add(ref pagenmbetal, ref first);


            object format = MSWord.WdSaveFormat.wdFormatDocument;
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            //Response.Write("<script>alert('" + path + ": Word文档格式设置完毕!');</script>");
            MessageBox.Show("操作完成");
        }

        //添加文本
        public void AddWordText()
        {
            object path;//文件路径
            string strContent;//文件内容
            MSWord.Application wordApp;//Word应用程序变量
            MSWord.Document wordDoc;//Word文档变量
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档
            wordApp = new MSWord.ApplicationClass();//初始化
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
            Object Nothing = Missing.Value;
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            wordApp.Selection.ParagraphFormat.LineSpacing = 35f;//设置文档的行间距
            //写入普通文本
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 30;//首行缩进的长度
            strContent = "c#向Word写入文本   普通文本:\n";
            wordDoc.Paragraphs.Last.Range.Text = strContent;

            //将文档的前三个字替换成"asdfasdf"，并将其颜色设为蓝色
            object start = 0;
            object end = 3;
            Microsoft.Office.Interop.Word.Range rang = wordDoc.Range(ref start, ref end);
            rang.Font.Color = Microsoft.Office.Interop.Word.WdColor.wdColorBrightGreen;
            rang.Text = "我是替换文字";
            wordDoc.Range(ref start, ref end);



            //写入黑体文本
            object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 0;//取消首行缩进的长度
            strContent = "黑体文本\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "黑体";
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            // wordApp.Selection.Text = strContent;
            //写入加粗文本
            strContent = "加粗文本\n ";
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            //  wordApp.Selection.Text = strContent;
            //写入15号字体文本
            strContent = "15号字体文本\n ";
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            wordDoc.Paragraphs.Last.Range.Font.Size = 15;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            //写入斜体文本
            strContent = "斜体文本\n ";
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordDoc.Paragraphs.Last.Range.Font.Italic = 1;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            //写入蓝色文本
            strContent = "蓝色文本\n ";
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordDoc.Paragraphs.Last.Range.Font.Color = MSWord.WdColor.wdColorBlue;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            //写入下划线文本
            strContent = "下划线文本\n ";
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordDoc.Paragraphs.Last.Range.Font.Underline = MSWord.WdUnderline.wdUnderlineThick;
            wordDoc.Paragraphs.Last.Range.Text = strContent;

            object format = MSWord.WdSaveFormat.wdFormatDocument;
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            //Response.Write("<script> alert('" + path + ": Word文档写入文本完毕!');</script>");
            MessageBox.Show("操作完成");
        }

        //添加图片
        public void AddWordPic()
        {
            object path;//文件路径
            string strContent;//文件内容
            MSWord.Application wordApp;//Word应用程序变量
            MSWord.Document wordDoc;//Word文档变量
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档
            wordApp = new MSWord.ApplicationClass();//初始化
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
            Object Nothing = Missing.Value;
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            string filename = "d:\\1.jpg";
            //定义要向文档中插入图片的位置
            object range = wordDoc.Paragraphs.Last.Range;
            //定义该图片是否为外部链接
            object linkToFile = false;//默认
            //定义插入的图片是否随word一起保存
            object saveWithDocument = true;
            //向word中写入图片
            wordDoc.InlineShapes.AddPicture(filename, ref Nothing, ref Nothing, ref Nothing);

            object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
            wordDoc.InlineShapes[1].Height = 130;
            wordDoc.InlineShapes[1].Width = 200;
            wordDoc.Content.InsertAfter("\n");
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            wordApp.Selection.Font.Size = 10;//字体大小
            wordApp.Selection.TypeText("图1 测试图片\n");


            object format = MSWord.WdSaveFormat.wdFormatDocument;
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            //Response.Write("<script>alert('" + path + ": Word文档创建图片完毕!');</script>");
            MessageBox.Show("操作完成");
        }

        //添加表格
        public void AddWordTable()
        {
            object path;//文件路径
            string strContent;//文件内容
            MSWord.Application wordApp;//Word应用程序变量
            MSWord.Document wordDoc;//Word文档变量
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档
            wordApp = new MSWord.ApplicationClass();//初始化
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
            Object Nothing = Missing.Value;
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);

            int tableRow = 6;
            int tableColumn = 6;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);


            wordDoc.Tables[1].Cell(1, 1).Range.Text = "列\n行";
            for (int i = 1; i < tableRow; i++)
            {
                for (int j = 1; j < tableColumn; j++)
                {
                    if (i == 1)
                    {
                        table.Cell(i, j + 1).Range.Text = "Column " + j;
                    }
                    if (j == 1)
                    {
                        table.Cell(i + 1, j).Range.Text = "Row " + i;
                    }
                    table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
                }
            }


            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //向新添加的行的单元格中添加图片
            string FileName = "d:\\CAD.jpg";//图片所在路径
            object LinkToFile = false;
            object SaveWithDocument = true;
            object Anchor = table.Cell(tableRow + 1, tableColumn).Range;//选中要添加图片的单元格
            wordDoc.Application.ActiveDocument.InlineShapes.AddPicture(FileName, ref LinkToFile, ref SaveWithDocument, ref Anchor);

            wordDoc.Application.ActiveDocument.InlineShapes[1].Width = 75;//图片宽度
            wordDoc.Application.ActiveDocument.InlineShapes[1].Height = 45;//图片高度
            // 将图片设置为四周环绕型
            MSWord.Shape s = wordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
            s.WrapFormat.Type = MSWord.WdWrapType.wdWrapSquare;


            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;

            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalBottom;
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleDouble;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            table.Rows[1].Range.Font.Bold = 1;
            table.Rows[1].Range.Font.Size = 12F;
            table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 40;//所有单元格的高度
            for (int i = 2; i <= tableRow; i++)
            {
                table.Rows[i].Height = 20;
            }
            table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 50;
            for (int i = 2; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 75;
            }


            //添加表头斜线,并设置表头的样式
            table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);

            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);

            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);

            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);

            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(4, 4).Merge(table.Cell(4, 5));//横向合并

            table.Cell(2, 3).Merge(table.Cell(4, 3));//纵向合并


            object format = MSWord.WdSaveFormat.wdFormatDocument;
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing);
            //Response.Write("<script>alert('" + path + ": Word文档创建表格完毕!');</script>");
        }

        //word书签使用
        public void AddDocModel()
        {
            MSWord.Application wordApp; //Word应用程序变量
            MSWord.Document wordDoc; //Word文档变量
            killWinWordProcess();
            wordApp = new ApplicationClass();
            wordApp.DisplayAlerts = WdAlertLevel.wdAlertsNone;
            wordApp.Visible = false;
            object missing = System.Reflection.Missing.Value;
            object templateName = System.Windows.Forms.Application.StartupPath + @"\1.doc";//最终的word文档需要写入的位置
            object ModelName = System.Windows.Forms.Application.StartupPath + @"\2.doc";//word模板的位置
            object count = 1;
            object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
            wordDoc = wordApp.Documents.Open(ref ModelName, ref missing, ref missing,
               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
               ref missing);//打开word模板

            //在书签处插入文字
            object oStart = "buwei";//word中的书签名 
            Range range = wordDoc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置 
            range.Text = "闸室底板";//在书签处插入文字内容
            oStart = "bianhao";//word中的书签名 
            Range range1 = wordDoc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置
            range1.Text = "012";//在书签处插入文字内容

            ////在书签处插入表格
            //oStart = "a";//word中的书签名 
            //range = wordDoc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置      
            //MSWord.Table tab_Pat = wordDoc.Tables.Add(range, 2, 4, ref missing, ref missing);//开辟一个2行4列的表格
            //tab_Pat.Range.Font.Size = 10.5F;
            //tab_Pat.Range.Font.Bold = 0;

            //tab_Pat.Columns[1].Width = 50;
            //tab_Pat.Columns[2].Width = 65;
            //tab_Pat.Columns[3].Width = 40;
            //tab_Pat.Columns[4].Width = 40;

            //tab_Pat.Cell(1, 1).Range.Text = "病历号";
            //tab_Pat.Cell(1, 2).Range.Text = "PatientNO";
            //tab_Pat.Cell(1, 3).Range.Text = "身高";
            //tab_Pat.Cell(1, 4).Range.Text = "Height";

            //tab_Pat.Cell(2, 1).Range.Text = "姓名";
            //tab_Pat.Cell(2, 2).Range.Text = "PatientName";
            //tab_Pat.Cell(2, 3).Range.Text = "体重";
            //tab_Pat.Cell(2, 4).Range.Text = "Weight";


            //保存word
            object format = WdSaveFormat.wdFormatDocument;//保存格式 
            wordDoc.SaveAs(ref templateName, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            //关闭wordDoc，wordApp对象              
            object SaveChanges = WdSaveOptions.wdSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
            object RouteDocument = false;
            wordDoc.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            wordApp.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            MessageBox.Show("操作完成");

        }
        #endregion

        //一键出表
        public void CreatWorkExplain(string strtext, string zhazhan, string jdkz, string jdkzrq, List<string> cs13, string jdkckz1, string jdkckz2, string jdkckz3, string jdgccg1, string jdkccg2, string jdkccg3, List<string> cs6, List<string> cs7, string dmdata, System.Data.DataTable dt, List<string> cs11, List<string> cs12,string dmzd,string bhtj)
        {

            object path;//文件路径
            string strContent;//文件内容
            MSWord.Application wordApp;//Word应用程序变量
            MSWord.Document wordDoc;//Word文档变量
            path = "d:\\myWord.doc";//保存为Word2003文档
            // path = "d:\\myWord.doc";//保存为Word2007文档
            string CADpath = "d:\\CAD.jpg";
            wordApp = new MSWord.ApplicationClass();//初始化
            object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            if (File.Exists((string)path))
            {
                File.Delete((string)path);
            }
           
            Object Nothing = Missing.Value;
            wordDoc = wordApp.Documents.Add(ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            //页面设置
            wordDoc.PageSetup.PaperSize = Microsoft.Office.Interop.Word.WdPaperSize.wdPaperA4;//设置纸张样式
            wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;//排列方式为垂直方向
            wordDoc.PageSetup.TopMargin = 57.0f;
            wordDoc.PageSetup.BottomMargin = 57.0f;
            wordDoc.PageSetup.LeftMargin = 57.0f;
            wordDoc.PageSetup.RightMargin = 57.0f;
            wordDoc.PageSetup.HeaderDistance = 30.0f;//页眉位置
            //设置页眉
            wordApp.ActiveWindow.View.Type = Microsoft.Office.Interop.Word.WdViewType.wdOutlineView;//视图样式
            wordApp.ActiveWindow.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekPrimaryHeader;//进入页眉设置，其中页眉边距在页面设置中已完成
            wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            //插入页眉图片(测试结果图片未插入成功)(Paragraph段落格式Format格式Alignment对齐)
            //wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;
            //string headerfile = "d:\\1.jpg";
            //Microsoft.Office.Interop.Word.InlineShape shape1 = wordApp.ActiveWindow.ActivePane.Selection.InlineShapes.AddPicture(headerfile, ref Nothing, ref Nothing, ref Nothing);
            //shape1.Height = 20;
            //shape1.Width = 80;
            wordApp.ActiveWindow.ActivePane.Selection.InsertAfter("2015年观测资料汇编                                                                           滨海抽水站");
            wordApp.ActiveWindow.ActivePane.Selection.Font.Bold = 0;
            wordApp.ActiveWindow.ActivePane.Selection.Font.Name = "宋体";//页眉的字体
            //去掉页眉的横线
            wordApp.ActiveWindow.ActivePane.Selection.ParagraphFormat.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].LineStyle = Microsoft.Office.Interop.Word.WdLineStyle.wdLineStyleSingle;
            wordApp.ActiveWindow.ActivePane.Selection.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom].Visible = false;
            wordApp.ActiveWindow.ActivePane.View.SeekView = Microsoft.Office.Interop.Word.WdSeekView.wdSeekMainDocument;//退出页眉设置
            //为当前页添加页码
            Microsoft.Office.Interop.Word.PageNumbers pns = wordApp.Selection.Sections[1].Headers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers;//获取当前页的号码
            pns.NumberStyle = Microsoft.Office.Interop.Word.WdPageNumberStyle.wdPageNumberStyleNumberInDash;
            pns.HeadingLevelForChapter = 0;
            pns.IncludeChapterNumber = false;
            pns.RestartNumberingAtSection = false;
            pns.StartingNumber = 0;
            object pagenmbetal = Microsoft.Office.Interop.Word.WdPageNumberAlignment.wdAlignPageNumberCenter;//将号码设置在中间
            object first = true;
            wordApp.Selection.Sections[1].Footers[Microsoft.Office.Interop.Word.WdHeaderFooterIndex.wdHeaderFooterEvenPages].PageNumbers.Add(ref pagenmbetal, ref first);


            //创建工作说明（strtext内容）
            CreatWorkExplian1(unite, Nothing, strtext, wordApp, wordDoc);

            //垂直位移标点线路示意图
            for (int i = 0; i < cs13.Count; i++)
            {
                InsertPicture(Nothing, wordApp, wordDoc, cs13[i]);
            }

            //垂直基点考证
            if (jdkz != "0")
            {
                CZWYGZJDKZB(unite, Nothing, wordApp, wordDoc, jdkz, jdkzrq);
            }


            //基点高程考证表（年份  闸站编号  本次观测日期）
            if (jdkckz1 != "0")
            {
                JDGCKZB(unite, Nothing, wordApp, wordDoc, zhazhan, jdkckz1, jdkckz2, jdkckz3);
            }


            //垂直位移观测成果表（年份  闸站编号，本次观测日期）
            if (jdgccg1 != "0")
            {
                CZWYGCB_old(unite, Nothing, wordApp, wordDoc, zhazhan, jdgccg1, jdkccg2, jdkccg3);
            }

            //垂直位移横断面分布图（年份  闸站编号）
            for (int i = 0; i < cs6.Count; i++)
            {
                InsertPicture(Nothing, wordApp, wordDoc, cs6[i]);
            }
            //垂直位移过程线（年份，闸站编号，部位）
            for (int i = 0; i < cs7.Count; i++)
            {
                InsertPicture(Nothing, wordApp, wordDoc, cs7[i]);
            }



            //标点考证
            CZWYGCBDKZB(unite, Nothing, wordApp, wordDoc);

            //垂直变化统计表（年份  闸站编号）
            
            if (bhtj!="0")
            {
                CZWYLBHTJB(unite, Nothing, wordApp, wordDoc,bhtj);
            }

            //河床断面桩号考证表（年份  闸站编号）
            if (dmzd!="0")
            {
                HCDMCLCGB(unite, Nothing, wordApp, wordDoc,dmzd);
            }

            //河床断面测量成果表（年份 闸站）
            if (dmdata != "0")
            {
                //for (int i = 0; i < dt.Rows.Count; i++)
                for (int i = 0; i < 1; i++)
                {
                    string sql = "select ID from DM_GCK where DmId='" + dt.Rows[i][0] + "'and obdate='" + dmdata + "'";
                    System.Data.DataTable dt1 = GetDataTable(sql);
                    string sql1 = "select PointId,Dis,DmObserveHit from dm_observe where ID='" + dt1.Rows[0][0].ToString() + "'";
                    System.Data.DataTable dt2 = GetDataTable(sql1);
                    HCDMZDGCKZB(unite, Nothing, wordApp, wordDoc, dt2, zhazhan, dt.Rows[i][0].ToString(), dt.Rows[i][1].ToString(),dmdata);
                }
            }
            //河床断面冲淤量比较表
            //HCDMCYLBJB(unite, Nothing, wordApp, wordDoc);
            //河道断面比较图
            for (int i = 0; i < cs11.Count; i++)
            {
                InsertPicture(Nothing, wordApp, wordDoc, cs11[i]);
            }
            //水下地形图
            for (int i = 0; i < cs12.Count; i++)
            {
                InsertPicture(Nothing, wordApp, wordDoc, cs12[i]);
            }
            //测压管水位统计（年份 闸站）
            //CYGSWTJB(unite, Nothing, wordApp, wordDoc);
            //测压管水位过程线
            //String path5 = @"D:\2015-滨海抽水站\水位过程线.jpg";
            // InsertPicture(Nothing, wordApp, wordDoc, path5);
            //测压管水位观测记录表
            //CYGSWGCJLB(unite, Nothing, wordApp, wordDoc);
            //CYGGKGCKZB(unite, Nothing, wordApp, wordDoc);
            //CYGLMDSYCGB(unite, Nothing, wordApp, wordDoc);
            //CYGYJGCCGB(unite, Nothing, wordApp, wordDoc);





            //关闭保存word
            object format = MSWord.WdSaveFormat.wdFormatDocument;
            wordDoc.SaveAs(ref path, ref format, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing, ref Nothing);
            wordDoc.Close(ref Nothing, ref Nothing, ref Nothing);
            wordApp.Quit(ref Nothing, ref Nothing, ref Nothing); //关闭wordApp组件对象
            //Response.Write("<script>alert('" + path + ": Word文档格式设置完毕!');</script>");
            MessageBox.Show("操作完成");
        }

        /// <summary>
        /// 工作说明写标题
        /// </summary>
        /// <param name="Nothing"></param>
        /// <param name="str">文本</param>
        public void CreatWorkExplian1(object unite, object Nothing, string str, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            //工作说明写标题

            wordApp.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "滨海抽水站2015年观测工作说明\n\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 25;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            // wordApp.Selection.Text = strContent;
            //写正文
            wordApp.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 50;//取消首行缩进的长度
            strContent = str;//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 15;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            // wordApp.Selection.Text = strContent;
        }

        /// <summary>
        /// 插入图片
        /// </summary>
        /// <param name="Nothing"></param>
        public void InsertPicture(object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc, string path)
        {
            //换页
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            wordApp.Selection.EndKey(ref myunit, ref mymissing); //将光标移动到文档末尾
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            wordApp.Selection.InsertBreak(ref pBreak);
            //定义要向文档中插入图片的位置
            object range = wordDoc.Paragraphs.Last.Range;
            //定义该图片是否为外部链接
            object linkToFile = false;//默认
            //定义插入的图片是否随word一起保存
            object saveWithDocument = true;
            //向word中写入图片
            wordDoc.InlineShapes.AddPicture(path, ref Nothing, ref Nothing, ref Nothing);
            wordApp.Selection.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//居中显示图片
            wordDoc.InlineShapes[k].Height = 620;
            wordDoc.InlineShapes[k].Width = 400;
            k = k + 1;
            //按比例缩放大小 
            //wordDoc.InlineShapes[1].ScaleWidth = 100;//缩小到20% ？
            //wordDoc.InlineShapes[1].ScaleHeight = 100;
            ////将图片设置为四周环绕型  
            //WdWrapType wdWrapType;
            //wdWrapType = Microsoft.Office.Interop.Word.WdWrapType.wdWrapSquare;
            //Microsoft.Office.Interop.Word.Shape s = wordDoc.Application.ActiveDocument.InlineShapes[1].ConvertToShape();
            //s.WrapFormat.Type = wdWrapType;           
            ////图片下插入文字
            //wordDoc.Content.InsertAfter("\n");
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphCenter;
            //wordApp.Selection.Font.Size = 10;//字体大小
            //wordApp.Selection.TypeText("图1 测试图片\n");

        }

        /// <summary>
        /// 垂直位移观测表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CZWYGCB_old(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc, string cs, string startTime, string frontTime, string thisTime)
        {
            int a = wordDoc.Characters.Count;
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //object myextend = Microsoft.Office.Interop.Word.wd
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = cs + "垂直位移观测成果表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            //绑定数据

            string sql = "select a.CdPosition ,a.CdId, a.Hit as Hit1 ,b.Hit as Hit2 ,c.Hit as Hit3 from result_observe a,(select CdPosition, CdId,Hit from result_observe where ObserDate ='" + startTime + "') b,(select CdPosition, CdId,Hit from result_observe where ObserDate ='" + frontTime + "') c where a.ObserDate ='" + thisTime + "' and a.CdId=b.CdId and b.CdId=c.CdId and a.CdPosition=b.CdPosition and b.CdPosition=c.CdPosition and a.BreakName='" + cs + "'";
            System.Data.DataTable dt = GetDataTable(sql);


            int tableRow = dt.Rows.Count + 3;
            int tableColumn = 8;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "始测日期";
            table.Cell(1, 3).Range.Text = startTime.ToString();
            table.Cell(1, 4).Range.Text = "上次观测日期";
            table.Cell(1, 5).Range.Text = frontTime.ToString();
            table.Cell(1, 6).Range.Text = "本次观测日期";
            table.Cell(1, 7).Range.Text = thisTime.ToString();
            table.Cell(1, 8).Range.Text = "间隔   天";
            table.Cell(2, 1).Range.Text = "测点";
            table.Cell(2, 3).Range.Text = "始测高程（米）";
            table.Cell(2, 4).Range.Text = "上次观测高程（米）";
            table.Cell(2, 5).Range.Text = "本次观测高程（米）";
            table.Cell(2, 6).Range.Text = "间隔位移量（毫米）";
            table.Cell(2, 7).Range.Text = "累计位移量（毫米）";
            table.Cell(2, 8).Range.Text = "备注";
            table.Cell(3, 1).Range.Text = "部位";
            table.Cell(3, 2).Range.Text = "编号";

            for (int i = 4; i < tableRow; i++)
            {
                for (int j = 0; j < 2; j++)
                {
                    table.Cell(i, j + 1).Range.Text = (string)dt.Rows[i - 4][j];
                }
                for (int j = 2; j < 5; j++)
                {
                    table.Cell(i, j + 1).Range.Text = dt.Rows[i - 4][j].ToString();
                }
                table.Cell(i, 6).Range.Text = (Math.Round(((double)dt.Rows[i - 4][4] - (double)dt.Rows[i - 4][3]) * 1000, 1)).ToString();
                table.Cell(i, 7).Range.Text = (Math.Round(((double)dt.Rows[i - 4][4] - (double)dt.Rows[i - 4][2]) * 1000, 1)).ToString();

            }
            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            //table.Rows.Add(ref Nothing);
            //table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 40;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            for (int i = 2; i <= tableRow; i++)
            {
                table.Rows[i].Height = 20;
            }
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 60;//将第 1列宽度设置为50
            table.Columns[2].Width = 40;
            //将其他列的宽度都设置为75
            for (int i = 3; i <= tableColumn - 1; i++)
            {
                table.Columns[i].Width = 60;
            }
            table.Columns[tableColumn].Width = 75;


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 1).Merge(table.Cell(1, 2));//横向合并
            table.Cell(2, 1).Merge(table.Cell(2, 2));
            table.Cell(2, 2).Merge(table.Cell(3, 3));//纵向合并
            table.Cell(2, 3).Merge(table.Cell(3, 4));
            table.Cell(2, 4).Merge(table.Cell(3, 5));
            table.Cell(2, 5).Merge(table.Cell(3, 6));
            table.Cell(2, 6).Merge(table.Cell(3, 7));
            table.Cell(2, 7).Merge(table.Cell(3, 8));

        }

        /// <summary>
        /// 基点高程考证表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        /// <param name="wordApp"></param>
        /// <param name="wordDoc"></param>
        public void JDGCKZB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc, string cs, string cs1, string cs2, string cs3)
        {
            //基点高程考证表
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            //wordApp.Selection.InsertBreak(ref pBreak);

            strContent = cs + "工作基点高程考证表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);


            string sql = "select a.JdId,a.JdConfirmDate,a.JdConfirmHit,b.JdConfirmDate as Date1,b.JdConfirmHit as Hit1 ,c.JdConfirmDate as Date2,c.JdConfirmHit as Hit2 from jd_confirm a,(select JdConfirmDate, JdConfirmHit,JdId from jd_confirm where BrakeId='" + cs + "'and JdConfirmDate ='" + cs1 + "') b,(select JdConfirmDate,JdConfirmHit,JdId from jd_confirm where BrakeId='" + cs + "'and JdConfirmDate ='" + cs2 + "') c where BrakeId='" + cs + "'and a.JdConfirmDate ='" + cs3 + "'and a.JdId=b.JdId and b.JdId=c.JdId";
            System.Data.DataTable dt = GetDataTable(sql);


            //插入表
            int tableRow = 20;
            int tableColumn = 8;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "基点编号";
            table.Cell(1, 2).Range.Text = "原始观测";
            table.Cell(1, 4).Range.Text = "上次观测";
            table.Cell(1, 6).Range.Text = "本次观测";
            table.Cell(1, 8).Range.Text = "备注";
            table.Cell(2, 2).Range.Text = "观测日期";
            table.Cell(2, 3).Range.Text = "高程";
            table.Cell(2, 4).Range.Text = "观测日期";
            table.Cell(2, 5).Range.Text = "高程";
            table.Cell(2, 6).Range.Text = "观测日期";
            table.Cell(2, 7).Range.Text = "高程";

            for (int i = 3; i < dt.Rows.Count + 3; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (j == 2 || j == 4 || j == 6)
                    {
                        table.Cell(i, j + 1).Range.Text = ((double)dt.Rows[i - 3][j]).ToString();

                    }
                    else
                    {
                        table.Cell(i, j + 1).Range.Text = (string)dt.Rows[i - 3][j];
                    }
                }

            }


            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 23;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            //for (int i = 2; i <= tableRow; i++)
            //{
            //    table.Rows[i].Height = 20;
            //}
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            //table.Columns[1].Width = 60;//将第 1列宽度设置为50
            // table.Columns[2].Width = 40;
            wordApp.Selection.Cells.Width = 108;
            //将其他列的宽度都设置为75
            for (int i = 1; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 58;
                i++;
            }

            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 2).Merge(table.Cell(1, 3));//横向合并
            table.Cell(1, 3).Merge(table.Cell(1, 4));//横向合并
            table.Cell(1, 4).Merge(table.Cell(1, 5));//横向合并
            table.Cell(1, 1).Merge(table.Cell(2, 1));//纵向合并
            table.Cell(1, 5).Merge(table.Cell(2, 8));//纵向合并

        }

        /// <summary>
        /// 河床断面桩顶高程考证表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        /// <param name="wordApp"></param>
        /// <param name="wordDoc"></param>
        public void HCDMCLCGB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc,string cs)
        {
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            //wordApp.Selection.InsertBreak(ref pBreak);

            strContent = cs+"河床断面桩顶高程考证表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            string sql11 = "select BrakeId,lczh,DmzPos,DmzMsDate,DmzConfirmDate,LeftHit,RightHit,Dmk  from dmz_confirm where BrakeId='" + cs + "'";
            System.Data.DataTable dt22 = GetDataTable(sql11);

            //插入表
            int tableRow = 25;
            int tableColumn = 9;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "断面编号";
            table.Cell(1, 2).Range.Text = "里程桩号";
            table.Cell(1, 3).Range.Text = "位置";
            table.Cell(1, 4).Range.Text = "埋设日期";
            table.Cell(1, 5).Range.Text = "观测日期";
            table.Cell(1, 6).Range.Text = "桩顶高程（m）";
            table.Cell(1, 8).Range.Text = "断面宽m";
            table.Cell(1, 9).Range.Text = "备注";
            table.Cell(2, 6).Range.Text = "左岸";
            table.Cell(2, 7).Range.Text = "右岸";
            for (int i = 0; i <dt22.Rows.Count; i++)
            {
                for (int j = 1; j <= 8; j++)
                {
                    table.Cell(i+3,j).Range.Text=dt22.Rows[i][j-1].ToString();
                }
            }
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 40;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 20;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            //for (int i = 2; i <= tableRow; i++)
            //{
            //    table.Rows[i].Height = 20;
            //}
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            //table.Columns[1].Width = 60;//将第 1列宽度设置为50
            // table.Columns[2].Width = 40;
            //wordApp.Selection.Cells.Width = 80;
            //将其他列的宽度都设置为75
            for (int i = 1; i <= 5; i++)
            {
                table.Columns[i].Width = 60;
            }
            for (int i = 6; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 40;
            }

            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 6).Merge(table.Cell(1, 7));//横向合并
            table.Cell(1, 1).Merge(table.Cell(2, 1));//纵向合并
            table.Cell(1, 2).Merge(table.Cell(2, 2));//纵向合并
            table.Cell(1, 3).Merge(table.Cell(2, 3));//纵向合并
            table.Cell(1, 4).Merge(table.Cell(2, 4));//纵向合并
            table.Cell(1, 5).Merge(table.Cell(2, 5));//纵向合并

        }

        /// <summary>
        /// 河床断面测量成果表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        /// <param name="wordApp"></param>
        /// <param name="wordDoc"></param>
        public void HCDMZDGCKZB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc, System.Data.DataTable dt,string cs,string cs1,string cs2,string cs3)
        {
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
           // wordApp.Selection.InsertBreak(ref pBreak);

            strContent = cs+"河床断面测量成果表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 20;
            int tableColumn = 9;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //这是插入的一个方法
            //object rownum = 1;
            //object colnum = 9;
            //table.Cell(1, 1).Split(ref rownum, ref colnum);
            //表格的索引是从1开始的
            table.Cell(2, 1).Range.Text = "点号";
            table.Cell(2, 2).Range.Text = "起点距（米）";
            table.Cell(2, 3).Range.Text = "高程（米）";
            table.Cell(2, 4).Range.Text = "点号";
            table.Cell(2, 5).Range.Text = "起点距（米）";
            table.Cell(2, 6).Range.Text = "高程（m）";
            table.Cell(2, 7).Range.Text = "点号";
            table.Cell(2, 8).Range.Text = "起点距（米）";
            table.Cell(2, 9).Range.Text = "高程（米）";

            for (int i = 1; i <= dt.Rows.Count; i++)
            {
                if (i <= 18)
                {
                    for (int j = 1; j <= 3; j++)
                    {
                        table.Cell(i + 2, j).Range.Text = dt.Rows[i - 1][j - 1].ToString();
                    }
                }
                else
                {
                    for (int j = 4; j <= 6; j++)
                    {
                        table.Cell(i + 2, j).Range.Text = dt.Rows[i - 1][j - 1].ToString();
                    }
                }
            }


            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 32;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            for (int i = 3; i <= tableRow; i++)
            {
                table.Rows[i].Height = 24;
            }
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            //table.Columns[1].Width = 60;//将第 1列宽度设置为50
            // table.Columns[2].Width = 40;
            //wordApp.Selection.Cells.Width = 80;
            //将其他列的宽度都设置为75
            for (int i = 1; i <= 9; i++)
            {
                table.Columns[i].Width = 37;
                i = i + 2;
            }
            for (int i = 2; i <= 9; i++)
            {
                table.Columns[i].Width = 67;
                i = i + 2;
            }
            for (int i = 3; i <= 9; i++)
            {
                table.Columns[i].Width = 52;
                i = i + 2;
            }



            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 2).Merge(table.Cell(1, 3));//横向合并
            table.Cell(1, 4).Merge(table.Cell(1, 5));//横向合并
            table.Cell(1, 6).Merge(table.Cell(1, 7));//横向合并

            table.Cell(1, 1).Width = 68;
            table.Cell(1, 2).Width = 88;
            table.Cell(1, 3).Width = 68;
            table.Cell(1, 4).Width = 88;
            table.Cell(1, 5).Width = 68;
            table.Cell(1, 6).Width = 88;

            table.Cell(1, 1).Range.Text = "断面编号";
            table.Cell(1, 3).Range.Text = "里程桩号";
            table.Cell(1, 5).Range.Text = "测量日期";
            table.Cell(1, 2).Range.Text = cs1;
            table.Cell(1, 4).Range.Text = cs2;
            table.Cell(1, 6).Range.Text = cs3;
            //写注释
            wordApp.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 0;//取消首行缩进的长度
            strContent = "注：起点距从左岸断面桩起算，向右为正，向左为负。";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 10;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
            wordDoc.Paragraphs.Last.Range.Text = strContent;

        }

        /// <summary>
        ///测压管水位统计表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CYGSWTJB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "滨海抽水站测压管水位统计表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 20;
            int tableColumn = 9;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "观测时间";
            table.Cell(1, 5).Range.Text = "水 位（米）";
            table.Cell(1, 7).Range.Text = "测压管水位（米）";
            table.Cell(2, 1).Range.Text = "月";
            table.Cell(2, 2).Range.Text = "日";
            table.Cell(2, 3).Range.Text = "时";
            table.Cell(2, 4).Range.Text = "分";
            table.Cell(2, 5).Range.Text = "上游";
            table.Cell(2, 6).Range.Text = "下游";
            table.Cell(2, 7).Range.Text = "011";
            table.Cell(2, 8).Range.Text = "012";
            table.Cell(2, 9).Range.Text = "013";
            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 25;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            //for (int i = 2; i <= tableRow; i++)
            //{
            //    table.Rows[i].Height = 20;
            //}
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            //table.Columns[1].Width = 60;//将第 1列宽度设置为50
            //table.Columns[2].Width = 40;
            //将其他列的宽度都设置为75
            for (int i = 1; i <= 4; i++)
            {
                table.Columns[i].Width = 35;
            }
            for (int i = 5; i < 10; i++)
            {
                table.Columns[i].Width = 75;
            }


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 1).Merge(table.Cell(1, 4));//横向合并
            table.Cell(1, 2).Merge(table.Cell(1, 3));
            table.Cell(1, 3).Merge(table.Cell(1, 5));
        }

        /// <summary>
        /// 测压管水位观测记录表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CYGSWGCJLB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "滨海抽水站测压管水位观测记录表\n\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;

            //写正文
            wordApp.Selection.EndKey(ref unite, ref Nothing); //将光标移动到文档末尾
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "观测日期：   年    月  日";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 15;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
            wordDoc.Paragraphs.Last.Range.Text = strContent;

            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 20;
            int tableColumn = 10;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "部位";
            table.Cell(1, 2).Range.Text = "编号";
            table.Cell(1, 3).Range.Text = "时间";
            table.Cell(1, 5).Range.Text = "压力表底座高程 m";
            table.Cell(1, 6).Range.Text = "压力表读数MPa";
            table.Cell(1, 7).Range.Text = "102P";
            table.Cell(1, 8).Range.Text = "测压管水位 m";
            table.Cell(1, 9).Range.Text = "上游水位 m";
            table.Cell(1, 10).Range.Text = "下游水位 m";
            table.Cell(2, 3).Range.Text = "时";
            table.Cell(2, 4).Range.Text = "分";
            table.Cell(3, 1).Range.Text = "站身左侧边墩";
            table.Cell(6, 1).Range.Text = "站身中墩";
            table.Cell(9, 1).Range.Text = "站身右侧边墩";
            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 12F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 25;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            //for (int i = 2; i <= tableRow; i++)
            //{
            //    table.Rows[i].Height = 20;
            //}
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 58;//将第 1列宽度设置为50
            table.Columns[2].Width = 40;
            table.Columns[3].Width = 25;
            table.Columns[4].Width = 25;

            //将其他列的宽度都设置为75
            for (int i = 5; i < 10; i++)
            {
                table.Columns[i].Width = 60;
            }


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 3).Merge(table.Cell(1, 4));//横向合并
            table.Cell(1, 1).Merge(table.Cell(2, 1));//纵向合并
            table.Cell(1, 2).Merge(table.Cell(2, 2));
            table.Cell(1, 4).Merge(table.Cell(2, 5));
            table.Cell(1, 5).Merge(table.Cell(2, 6));
            table.Cell(1, 6).Merge(table.Cell(2, 7));
            table.Cell(1, 7).Merge(table.Cell(2, 8));
            table.Cell(1, 8).Merge(table.Cell(2, 9));
            table.Cell(1, 9).Merge(table.Cell(2, 10));
            //table.Cell(2, 1).Merge(table.Cell(4, 1));
            table.Cell(3, 1).Merge(table.Cell(5, 1));
            table.Cell(6, 1).Merge(table.Cell(8, 1));
            table.Cell(9, 1).Merge(table.Cell(11, 1));
        }

        /// <summary>
        /// 测压管管口高程考证表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CYGGKGCKZB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "滨海抽水站测压管管口高程考证表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 21;
            int tableColumn = 7;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "编号";
            table.Cell(1, 2).Range.Text = "埋设日期";
            table.Cell(1, 3).Range.Text = "始测日期";
            table.Cell(1, 4).Range.Text = "始测高程";
            table.Cell(1, 5).Range.Text = "考证日期";
            table.Cell(1, 6).Range.Text = "考证高程";
            table.Cell(1, 7).Range.Text = "备注";

            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 40;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            for (int i = 2; i <= tableRow + 1; i++)
            {
                table.Rows[i].Height = 25;
            }
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 45;//将第 1列宽度设置为50
            //将其他列的宽度都设置为75
            for (int i = 2; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 60;
            }


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            for (int i = 2; i < tableRow + 1; i++)
            {
                table.Cell(i, 7).Merge(table.Cell(i + 2, 7));//纵向合并
                i += 2;
            }
        }

        /// <summary>
        /// 测压管灵敏度试验成果表（插入标签/尚未完成）
        /// </summary>
        public void CYGLMDSYCGB_model(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            MSWord.Application wordApp1; //Word应用程序变量
            MSWord.Document wordDoc1; //Word文档变量
            //killWinWordProcess();
            wordApp1 = new ApplicationClass();
            wordApp1.DisplayAlerts = WdAlertLevel.wdAlertsNone;
            wordApp1.Visible = false;
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object missing = System.Reflection.Missing.Value;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            object templateName = @"D:\myWord.doc";//最终的word文档需要写入的位置
            object ModelName = @"D:\model.doc";//word模板的位置
            object count = 1;
            object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdLine;//换一行;
            wordDoc1 = wordApp1.Documents.Open(ref ModelName, ref missing, ref missing,
               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
               ref missing, ref missing, ref missing, ref missing, ref missing, ref missing,
               ref missing);//打开word模板

            //在书签处插入文字
            object oStart = "buwei";//word中的书签名 
            Range range = wordDoc1.Bookmarks.get_Item(ref oStart).Range;//表格插入位置 
            range.Text = "闸室底板";//在书签处插入文字内容
            oStart = "bianhao";//word中的书签名 
            Range range1 = wordDoc1.Bookmarks.get_Item(ref oStart).Range;//表格插入位置
            range1.Text = "012";//在书签处插入文字内容

            ////在书签处插入表格
            //oStart = "a";//word中的书签名 
            //range = wordDoc.Bookmarks.get_Item(ref oStart).Range;//表格插入位置      
            //MSWord.Table tab_Pat = wordDoc.Tables.Add(range, 2, 4, ref missing, ref missing);//开辟一个2行4列的表格
            //tab_Pat.Range.Font.Size = 10.5F;
            //tab_Pat.Range.Font.Bold = 0;

            //tab_Pat.Columns[1].Width = 50;
            //tab_Pat.Columns[2].Width = 65;
            //tab_Pat.Columns[3].Width = 40;
            //tab_Pat.Columns[4].Width = 40;

            //tab_Pat.Cell(1, 1).Range.Text = "病历号";
            //tab_Pat.Cell(1, 2).Range.Text = "PatientNO";
            //tab_Pat.Cell(1, 3).Range.Text = "身高";
            //tab_Pat.Cell(1, 4).Range.Text = "Height";

            //tab_Pat.Cell(2, 1).Range.Text = "姓名";
            //tab_Pat.Cell(2, 2).Range.Text = "PatientName";
            //tab_Pat.Cell(2, 3).Range.Text = "体重";
            //tab_Pat.Cell(2, 4).Range.Text = "Weight";

            //换页
            //wordApp.Selection.EndKey(ref myunit, ref mymissing);
            //wordApp.Selection.InsertBreak(ref pBreak);


            //保存word
            object format = WdSaveFormat.wdFormatDocument;//保存格式 
            wordDoc1.SaveAs(ref templateName, ref format, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing, ref missing);
            //关闭wordDoc，wordApp对象              
            object SaveChanges = WdSaveOptions.wdSaveChanges;
            object OriginalFormat = WdOriginalFormat.wdOriginalDocumentFormat;
            object RouteDocument = false;
            wordDoc1.Close(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            wordApp1.Quit(ref SaveChanges, ref OriginalFormat, ref RouteDocument);
            MessageBox.Show("操作完成");

        }

        /// <summary>
        /// 测压管灵敏度试验成果表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CYGLMDSYCGB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "测压管灵敏度试验成果表\n\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            //写正文
            wordApp.Selection.ParagraphFormat.FirstLineIndent = 30;//取消首行缩进的长度
            string str1 = "闸室底板";
            string str2 = "012";
            string str3 = "09:12:16";
            string str4 = "2015-11-15";
            string str5 = "24L";
            string str6 = "09:12:16";
            strContent = string.Format("部位:{0}      测压管编号:{1}      注（放）水开始时间:{2}\n\n日期:{3}    注（放）水量:{4}    注（放）水结束时间:{5}\n\n", str1, str2, str3, str4, str5, str6);
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            //wordDoc.Paragraphs.Last.Range.Font.Underline = MSWord.WdUnderline.wdUnderlineSingle;
            //InsertUnderLine(strContent, wordApp);
            wordDoc.Paragraphs.Last.Range.Font.Size = 10;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphLeft;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            //插入表
            int tableRow = 18;
            int tableColumn = 5;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "资料名称";
            table.Cell(1, 2).Range.Text = "累计时间";
            table.Cell(1, 3).Range.Text = "管口至水面距离（米）";
            table.Cell(1, 4).Range.Text = "测压管水位（米）";
            table.Cell(1, 5).Range.Text = "备注";
            table.Cell(2, 1).Range.Text = "注（放）水前管中水位（米）";
            table.Cell(3, 1).Range.Text = "注（放）水后管中水位（米）";
            table.Cell(4, 1).Range.Text = "注（放）水后各时段管中水位";
            table.Cell(18, 1).Range.Text = "结论：\n\n测压管灵敏度      （优/劣）        平均水头落（涨）差     厘米/小时\n\n  注（放）水后经过     小时恢复水位    最大水头落（涨）差     厘米/小时";


            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）
            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 20;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            table.Rows[1].Height = 50;
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 140;//将第 1列宽度设置为50
            table.Columns[2].Width = 60;
            table.Columns[3].Width = 90;
            table.Columns[4].Width = 70;
            table.Columns[5].Width = 80;


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(18, 1).Merge(table.Cell(19, 5));//横向合并
            table.Cell(4, 1).Merge(table.Cell(17, 1));//纵向合并
            table.Cell(2, 5).Merge(table.Cell(17, 5));
        }


        /// <summary>
        /// 垂直位移工作基点考证表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CZWYGZJDKZB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc, string cs1, string cs2)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "垂直位移工作基点考证表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);

            string sql = "select a.JdId,a.JdMat,a.JdDate,a.JdPos,a.JdSit,b.JdConfirmDate,b.JdConfirmHit from jd_info a,jd_confirm b where a.BrakeId='" + cs1 + "'and a.JdDate='" + cs2 + "'and a.BrakeId=b.BrakeId and a.JdId=b.JdId";
            System.Data.DataTable dt = GetDataTable(sql);

            //插入表
            int tableRow = 20;
            int tableColumn = 8;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "基点编号";
            table.Cell(1, 2).Range.Text = "标点材料";
            table.Cell(1, 3).Range.Text = "埋设日期";
            table.Cell(1, 4).Range.Text = "位置";
            table.Cell(1, 5).Range.Text = "地基情况";
            table.Cell(1, 6).Range.Text = "考证日期";
            table.Cell(1, 7).Range.Text = "高程m";
            table.Cell(1, 8).Range.Text = "备注";
            table.Cell(15, 1).Range.Text = "标点位置及位置图";




            for (int i = 2; i < dt.Rows.Count + 2; i++)
            {
                for (int j = 0; j < 7; j++)
                {
                    if (j == 6)
                    {
                        table.Cell(i, j + 1).Range.Text = ((double)dt.Rows[i - 2][j]).ToString();
                    }
                    else
                    {
                        table.Cell(i, j + 1).Range.Text = ((string)dt.Rows[i - 2][j]);
                    }
                }
            }
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 25;//所有单元格的高度
            wordApp.Selection.Cells.Width = 55;
            //除第一行外，其他行的行高都设置为20
            //for (int i = 2; i <= tableRow; i++)
            //{
            //    table.Rows[i].Height = 20;
            //}
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            //table.Columns[1].Width = 60;//将第 1列宽度设置为50
            //table.Columns[2].Width = 40;
            ////将其他列的宽度都设置为75
            //for (int i = 3; i <= tableColumn - 1; i++)
            //{
            //    table.Columns[i].Width = 60;
            //}
            //table.Columns[tableColumn].Width = 75;


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(15, 1).Merge(table.Cell(21, 8));//横向合并
        }

        /// <summary>
        /// 垂直位移观测标点考证表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CZWYGCBDKZB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "垂直位移观测标点考证表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 20;
            int tableColumn = 8;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "标点";
            table.Cell(1, 3).Range.Text = "埋设日期";
            table.Cell(1, 4).Range.Text = "原始点（末次）";
            table.Cell(1, 6).Range.Text = "新标点";
            table.Cell(1, 8).Range.Text = "备注";
            table.Cell(2, 1).Range.Text = "部位";
            table.Cell(2, 2).Range.Text = "编号";
            table.Cell(2, 4).Range.Text = "观测日期";
            table.Cell(2, 5).Range.Text = "高程";
            table.Cell(2, 6).Range.Text = "考证日期";
            table.Cell(2, 7).Range.Text = "高程";
            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 12F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 25;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            table.Rows[2].Height = 40;
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;
            //将其他列的宽度都设置为75
            for (int i = 1; i <= tableColumn - 1; i++)
            {
                table.Columns[i].Width = 60;
            }
            table.Columns[tableColumn].Width = 75;


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 1).Merge(table.Cell(1, 2));//横向合并
            table.Cell(1, 3).Merge(table.Cell(1, 4));
            table.Cell(1, 4).Merge(table.Cell(1, 5));
            table.Cell(1, 2).Merge(table.Cell(2, 3));//纵向合并
        }

        /// <summary>
        ///测压管淤积观测成果表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CYGYJGCCGB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientPortrait;
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            strContent = "测压管淤积观测成果表\n ";//在文本中使用'\n'换行
            wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            wordDoc.Paragraphs.Last.Range.Font.Size = 20;
            wordDoc.Paragraphs.Last.Range.Font.Bold = 1;//Bold=0为不加粗
            wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            wordDoc.Paragraphs.Last.Range.Text = strContent;
            wordApp.Selection.EndKey(ref unite, ref Nothing);
            //插入表
            int tableRow = 20;
            int tableColumn = 7;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "上次观测时间";
            table.Cell(1, 4).Range.Text = "本次观测日期";
            table.Cell(1, 7).Range.Text = "间隔   天";
            table.Cell(2, 1).Range.Text = "测压管";
            table.Cell(2, 3).Range.Text = "管口高程m";
            table.Cell(2, 4).Range.Text = "管底高程m";
            table.Cell(2, 5).Range.Text = "淤积厚度m";
            table.Cell(2, 7).Range.Text = "备注";
            table.Cell(3, 1).Range.Text = "部位";
            table.Cell(3, 2).Range.Text = "编号";
            table.Cell(3, 5).Range.Text = "上次观测";
            table.Cell(3, 6).Range.Text = "本地观测";
            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 25;//所有单元格的高度
            table.Rows[2].Height = 40;
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 60;//将第 1列宽度设置为50
            table.Columns[2].Width = 60;
            //将其他列的宽度都设置为75
            for (int i = 3; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 75;
            }

            int a = wordDoc.Characters.Count;
            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 1).Merge(table.Cell(1, 2));//横向合并
            table.Cell(1, 3).Merge(table.Cell(1, 4));
            table.Cell(2, 1).Merge(table.Cell(2, 2));
            table.Cell(2, 4).Merge(table.Cell(2, 5));
            table.Cell(2, 2).Merge(table.Cell(3, 3));//纵向合并
            table.Cell(2, 3).Merge(table.Cell(3, 4));
        }

        /// <summary>
        /// 垂直位移量变化统计表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void CZWYLBHTJB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc,string cs)
        {
            string str111 = cs;
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            //wordApp.Selection.InsertBreak(ref pBreak);

            //绑定数据
            string sql = "select distinct ObserDate from result_observe where BreakName='" + str111 + "'order by ObserDate desc";//可以将获取的时间数据倒着赋值给一个容量为14的数组
            System.Data.DataTable dt = GetDataTable(sql);
            string[] str1 = new string[14];
            int a = dt.Rows.Count;
            for (int i = 0; i < 14; i++)
            {
                str1[i] = Convert.ToDateTime(dt.Rows[13 - i][0]).ToString("yyyy-MM-dd");
            }
            //获取前两列数据
            string SQL = "select CdPart,CdId from cd_info where BrakeId='" + str111 + "'order by CdPart";
            System.Data.DataTable dt1 = GetDataTable(SQL);
            DataSet ds = new DataSet();

            //获取累计位移量
            string[] sql2 = new string[14];
            for (int i = 0; i < 14; i++)
            {

                sql2[i] = "select Ljwyl as '" + (i + 1) + "'from LJWYL where BreakName='" + str111 + "'and ObserDate='" + str1[i] + "'";
                // System.Data.DataTable dt2 = GetDataTable(sql2);
                // ds = DbHelperSQL.Query(sql2[i]);
            }
            System.Data.DataTable dt2 = GetDataTable(sql2[0]);
            System.Data.DataTable dt3 = GetDataTable(sql2[1]);
            System.Data.DataTable dt4 = GetDataTable(sql2[2]);
            System.Data.DataTable dt5 = GetDataTable(sql2[3]);
            System.Data.DataTable dt6 = GetDataTable(sql2[4]);
            System.Data.DataTable dt7 = GetDataTable(sql2[5]);
            System.Data.DataTable dt8 = GetDataTable(sql2[6]);
            System.Data.DataTable dt9 = GetDataTable(sql2[7]);
            System.Data.DataTable dt10 = GetDataTable(sql2[8]);
            System.Data.DataTable dt11 = GetDataTable(sql2[9]);
            System.Data.DataTable dt12 = GetDataTable(sql2[10]);
            System.Data.DataTable dt13 = GetDataTable(sql2[11]);
            System.Data.DataTable dt14 = GetDataTable(sql2[12]);
            System.Data.DataTable dt15 = GetDataTable(sql2[13]);
            //for (int i = 0; i < 14; i++)
            //{
            //     dt1.Columns.Add("i");
            //}  
            //dt2.Columns.Add("1");
            //dt2.Columns.Add("1");
            dt2.Columns.Add("2");
            dt2.Columns.Add("3");
            dt2.Columns.Add("4");
            dt2.Columns.Add("5");
            dt2.Columns.Add("6");
            dt2.Columns.Add("7");
            dt2.Columns.Add("8");
            dt2.Columns.Add("9");
            dt2.Columns.Add("10");
            dt2.Columns.Add("11");
            dt2.Columns.Add("12");
            dt2.Columns.Add("13");
            dt2.Columns.Add("14");

            for (int i = 0; i < dt2.Rows.Count; i++)
            {

                dt2.Rows[i]["2"] = dt3.Rows[i]["2"];
                dt2.Rows[i]["3"] = dt4.Rows[i]["3"];
                dt2.Rows[i]["4"] = dt5.Rows[i]["4"];
                dt2.Rows[i]["5"] = dt6.Rows[i]["5"];
                dt2.Rows[i]["6"] = dt7.Rows[i]["6"];
                dt2.Rows[i]["7"] = dt8.Rows[i]["7"];
                dt2.Rows[i]["8"] = dt9.Rows[i]["8"];
                dt2.Rows[i]["9"] = dt10.Rows[i]["9"];
                dt2.Rows[i]["10"] = dt11.Rows[i]["10"];
                dt2.Rows[i]["11"] = dt12.Rows[i]["11"];
                dt2.Rows[i]["12"] = dt13.Rows[i]["12"];
                dt2.Rows[i]["13"] = dt14.Rows[i]["13"];
                dt2.Rows[i]["14"] = dt15.Rows[i]["14"];


            }


            

            //生成横版
            Object oMissing = System.Reflection.Missing.Value;
            object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
            object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage;//分页符
            wordApp.Selection.InsertBreak(ref oPageBreak);
            wordApp.Selection.MoveDown(WdLine, 2, oMissing);
            wordApp.Selection.InsertBreak(ref oPageBreak);
            wordApp.Selection.MoveUp(WdLine, 1, oMissing);
            wordApp.Selection.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;

            int tableRow = dt1.Rows.Count + 3;
            int tableColumn = 16;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "滨海抽水站垂直位移量变化统计表";
            table.Cell(2, 1).Range.Text = "测点";
            table.Cell(2, 3).Range.Text = "累计位移量(mm)";
            table.Cell(3, 1).Range.Text = "部位";
            table.Cell(3, 2).Range.Text = "编号";
            for (int i = 3; i < 17; i++)
            {
                table.Cell(3, i).Range.Text = str1[i - 3];
            }

            //写入前两列数据
            for (int i = 4; i < dt1.Rows.Count + 4; i++)//行
            {
                for (int j = 0; j < 2; j++)//列
                {
                    table.Cell(i, j + 1).Range.Text = ((string)dt1.Rows[i - 4][j]);

                }
            }
            //写入累计位移量
            for (int i = 4; i < dt2.Rows.Count + 4; i++)//行
            {
                for (int j = 0; j < 14; j++)
                {
                    table.Cell(i, j + 3).Range.Text = (Convert.ToDouble(dt2.Rows[i - 4][j])).ToString();

                }
            }



            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 20;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            table.Rows[1].Height = 70;
            table.Rows[2].Height = 45;
            table.Rows[3].Height = 70;
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 60;//将第 1列宽度设置为50
            table.Columns[2].Width = 35;
            //将其他列的宽度都设置为75
            for (int i = 3; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 45;
            }


            table.Cell(1, 1).Range.Font.Size = 25F;
            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            table.Cell(1, 1).Merge(table.Cell(1, 16));//横向合并
            table.Cell(2, 1).Merge(table.Cell(2, 2));
            table.Cell(2, 2).Merge(table.Cell(2, 15));

            MSWord.WdStatistic stat = MSWord.WdStatistic.wdStatisticPages;
            int num = wordDoc.ComputeStatistics(stat, ref  Nothing);
        }


        /// <summary>
        /// 河床断面冲淤量比较表
        /// </summary>
        /// <param name="unite"></param>
        /// <param name="Nothing"></param>
        public void HCDMCYLBJB(object unite, object Nothing, MSWord.Application wordApp, MSWord.Document wordDoc)
        {
            int a = wordDoc.Characters.Count;
            object mymissing = System.Reflection.Missing.Value;
            object myunit = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //object myextend = Microsoft.Office.Interop.Word.wd
            object pBreak = (int)Microsoft.Office.Interop.Word.WdBreakType.wdPageBreak;
            //换页
            wordApp.Selection.EndKey(ref myunit, ref mymissing);
            //wordApp.Selection.InsertBreak(ref pBreak);
            //wordDoc.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;
            //object unite = Microsoft.Office.Interop.Word.WdUnits.wdStory;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);
            //wordApp.Selection.ParagraphFormat.FirstLineIndent = 10;//取消首行缩进的长度
            //strContent = "滨海抽水站河床断面冲淤量比较表\n ";//在文本中使用'\n'换行
            //wordDoc.Paragraphs.Last.Range.Font.Name = "宋体";
            //wordDoc.Paragraphs.Last.Range.Font.Size = 18;
            //wordDoc.Paragraphs.Last.Range.Font.Bold = 0;//Bold=0为不加粗
            //wordDoc.Paragraphs.Last.Alignment = WdParagraphAlignment.wdAlignParagraphCenter;
            //wordDoc.Paragraphs.Last.Range.Text = strContent;
            //wordApp.Selection.EndKey(ref unite, ref Nothing);


            //生成横版
            Object oMissing = System.Reflection.Missing.Value;
            object WdLine = Microsoft.Office.Interop.Word.WdUnits.wdParagraph;
            object oPageBreak = Microsoft.Office.Interop.Word.WdBreakType.wdSectionBreakNextPage;//分页符
            wordApp.Selection.InsertBreak(ref oPageBreak);
            wordApp.Selection.MoveDown(WdLine, 2, oMissing);
            wordApp.Selection.InsertBreak(ref oPageBreak);
            wordApp.Selection.MoveUp(WdLine, 1, oMissing);
            wordApp.Selection.PageSetup.Orientation = Microsoft.Office.Interop.Word.WdOrientation.wdOrientLandscape;



            //绑定数据

            //string sql = "select a.CdPosition ,a.CdId, a.Hit as Hit1 ,b.Hit as Hit2 ,c.Hit as Hit3 from result_observe a,(select CdPosition, CdId,Hit from result_observe where ObserDate ='2011-03-17') b,(select CdPosition, CdId,Hit from result_observe where ObserDate ='2015-03-19') c where a.ObserDate ='2015-11-03' and a.CdId=b.CdId and b.CdId=c.CdId and a.CdPosition=b.CdPosition and b.CdPosition=c.CdPosition";
            //System.Data.DataTable dt = GetDataTable(sql);


            int tableRow = 30;
            int tableColumn = 17;
            //定义一个word中的表格对象
            MSWord.Table table = wordDoc.Tables.Add(wordApp.Selection.Range, tableRow, tableColumn, ref Nothing, ref Nothing);
            //表格的索引是从1开始的
            table.Cell(1, 1).Range.Text = "滨海抽水站河床断面冲淤量比较表\n\n工程竣工日期  2009-12-1  上次观测日期 2014-10-12  本次观测日期  2015-3-25  计算水位 4.00 米";
            table.Cell(2, 1).Range.Text = "断面编号";
            table.Cell(2, 2).Range.Text = "里程";
            table.Cell(2, 3).Range.Text = "计算水位断面宽（m）";
            table.Cell(2, 6).Range.Text = "深泓高程(m) ";
            table.Cell(2, 9).Range.Text = "断面积（m2）";
            table.Cell(2, 12).Range.Text = "断面间距（m）";
            table.Cell(2, 13).Range.Text = "河床容积（m 3 ）";
            table.Cell(2, 16).Range.Text = "间隔冲於量（m 3 ）";
            table.Cell(2, 17).Range.Text = "累计冲於量（m 3 ）";
            table.Cell(3, 3).Range.Text = "标准断面";
            table.Cell(3, 4).Range.Text = "上次观测";
            table.Cell(3, 5).Range.Text = "本次观测";
            table.Cell(3, 6).Range.Text = "标准断面";
            table.Cell(3, 7).Range.Text = "上次观测";
            table.Cell(3, 8).Range.Text = "本次观测";
            table.Cell(3, 9).Range.Text = "标准断面";
            table.Cell(3, 10).Range.Text = "上次观测";
            table.Cell(3, 11).Range.Text = "本次观测";
            table.Cell(3, 13).Range.Text = "标准断面";
            table.Cell(3, 14).Range.Text = "上次观测";
            table.Cell(3, 15).Range.Text = "本次观测";



            //for (int i = 1; i < tableRow; i++)
            //{
            //    for (int j = 1; j < tableColumn; j++)
            //    {
            //        if (i == 1)
            //        {
            //            table.Cell(i, j + 1).Range.Text = "Column " + j;
            //        }
            //        if (j == 1)
            //        {
            //            table.Cell(i + 1, j).Range.Text = "Row " + i;
            //        }
            //        table.Cell(i + 1, j + 1).Range.Text = i + "行 " + j + "列";
            //    }
            //}
            //添加行
            table.Rows.Add(ref Nothing);
            table.Rows[tableRow + 1].Height = 45;
            //设置table样式
            table.Rows.HeightRule = MSWord.WdRowHeightRule.wdRowHeightAtLeast;//列高度至少会是指定的最小值。
            table.Rows.Height = wordApp.CentimetersToPoints(float.Parse("0.8"));//将计量单位从厘米转换为磅（一磅等于 0.035 厘米）

            table.Range.Font.Size = 10.5F;
            table.Range.Font.Bold = 0;
            table.Rows.Alignment = WdRowAlignment.wdAlignRowCenter;//表格居中
            table.Range.ParagraphFormat.Alignment = MSWord.WdParagraphAlignment.wdAlignParagraphCenter;//表格文本居中
            table.Range.Cells.VerticalAlignment = MSWord.WdCellVerticalAlignment.wdCellAlignVerticalCenter;//文本垂直贴到底部
            //设置table边框样式
            table.Borders.OutsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;
            table.Borders.InsideLineStyle = MSWord.WdLineStyle.wdLineStyleSingle;

            //table.Rows[1].Range.Font.Bold = 0;
            //table.Rows[1].Range.Font.Size = 12F;
            //table.Cell(1, 1).Range.Font.Size = 10.5F;
            wordApp.Selection.Cells.Height = 15;//所有单元格的高度
            //除第一行外，其他行的行高都设置为20
            table.Rows[1].Height = 25;
            table.Rows[2].Height = 25;
            table.Rows[3].Height = 45;
            //将表格左上角的单元格里的文字（“行” 和 “列”）居右
            //table.Cell(1, 1).Range.ParagraphFormat.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphRight;
            //将表格左上角的单元格里面下面的“列”字移到左边，相比上一行就是将ParagraphFormat改成了Paragraphs[2].Format
            //table.Cell(1, 1).Range.Paragraphs[2].Format.Alignment = Microsoft.Office.Interop.Word.WdParagraphAlignment.wdAlignParagraphLeft;

            table.Columns[1].Width = 60;//将第 1列宽度设置为50
            table.Columns[2].Width = 50;
            //将其他列的宽度都设置为75
            for (int i = 3; i <= tableColumn; i++)
            {
                table.Columns[i].Width = 45;
            }


            //添加表头斜线,并设置表头的样式
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Visible = true;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGray60;
            //table.Cell(1, 1).Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderDiagonalDown].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;

            //表格边框
            //表格内容行边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderHorizontal, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            //表格内容列边框
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical, Microsoft.Office.Interop.Word.WdColor.wdColorGray20, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth025pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderRight, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderTop, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            SetTableBorderStyle(table, Microsoft.Office.Interop.Word.WdBorderType.wdBorderBottom, Microsoft.Office.Interop.Word.WdColor.wdColorGray50, Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt);
            //合并单元格
            for (int i = 4; i < 30; i++)
            {
                for (int j = 1; j <= 11; j++)
                {
                    table.Cell(i, j).Merge(table.Cell(i + 1, j));
                }
                for (int j = 12; j <= 17; j++)
                {
                    table.Cell(i + 1, j).Merge(table.Cell(i + 2, j));
                }
                i++;
            }
            table.Cell(1, 1).Merge(table.Cell(1, 17));//横向合并
            table.Cell(2, 3).Merge(table.Cell(2, 5));
            table.Cell(2, 4).Merge(table.Cell(2, 6));
            table.Cell(2, 5).Merge(table.Cell(2, 7));
            table.Cell(2, 7).Merge(table.Cell(2, 9));
            table.Cell(2, 1).Merge(table.Cell(3, 1));//纵向合并
            table.Cell(2, 2).Merge(table.Cell(3, 2));
            table.Cell(2, 6).Merge(table.Cell(3, 12));
            table.Cell(2, 8).Merge(table.Cell(3, 16));
            table.Cell(2, 9).Merge(table.Cell(3, 17));

            // 计算Word文档页数
            //MSWord.WdStatistic stat = MSWord.WdStatistic.wdStatisticPages;
            //int num = wordDoc.ComputeStatistics(stat, ref  Nothing);

            //DeletePage(num-1, wordDoc);

        }


        /// <summary>
        /// 加下划线
        /// </summary>
        /// <param name="pText"></param>
        /// <param name="wordApp"></param>
        public void InsertUnderLine(string pText, MSWord.Application wordApp)
        {
            wordApp.Selection.TypeText(pText);
            wordApp.Selection.Font.Underline = Microsoft.Office.Interop.Word.WdUnderline.wdUnderlineSingle; //设置下划线
        }


        /// <summary>
        /// 设置边框
        /// </summary>
        /// <param name="table"></param>
        /// <param name="wdBorderType"></param>
        /// <param name="wdColor"></param>
        /// <param name="wdLineWidth"></param>
        private void SetTableBorderStyle(Table table, WdBorderType wdBorderType, WdColor wdColor, WdLineWidth wdLineWidth)
        {
            table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderVertical].Visible = true;
            table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].Color = Microsoft.Office.Interop.Word.WdColor.wdColorGreen;

            table.Borders[Microsoft.Office.Interop.Word.WdBorderType.wdBorderLeft].LineWidth = Microsoft.Office.Interop.Word.WdLineWidth.wdLineWidth050pt;
        }

        //插入分页符
        //public static void InsertBreak()
        //{
        //    Microsoft.Office.Interop.Word.Paragraph para;
        //    para = wordDoc.Content.Paragraphs.Add(ref Nothing);
        //    object pBreak = (int)WdBreakType.wdSectionBreakNextPage;
        //    para.Range.InsertBreak(ref pBreak);
        //}

        /// <summary>
        /// 杀掉winword.exe进程
        /// </summary>   
        public void killWinWordProcess()
        {
            System.Diagnostics.Process[] processes = System.Diagnostics.Process.GetProcessesByName("WINWORD");
            foreach (System.Diagnostics.Process process in processes)
            {
                bool b = process.MainWindowTitle == "";
                if (process.MainWindowTitle == "")
                {
                    process.Kill();
                }
            }
        }

        /// <summary>
        /// 执行查询语句，返回DataTable
        /// </summary>
        /// <param name="sql">查询语句</param>
        /// <returns>DataTable</returns>
        public System.Data.DataTable GetDataTable(string sql)
        {
            using (SqlConnection conn = new SqlConnection(str))
            {
                System.Data.DataTable dt = new System.Data.DataTable();
                try
                {
                    SqlDataAdapter command = new SqlDataAdapter(sql, conn);
                    command.Fill(dt);
                }
                catch (SqlException ex)
                {

                    throw new Exception(ex.Message);
                }
                return dt;
            }
        }


        public int PageCount
        {
            get
            {
                object oMissing = System.Reflection.Missing.Value;

                int pageCount = wordDoc.ComputeStatistics(WdStatistic.wdStatisticPages, oMissing);

                return pageCount;
            }
        }

        public Range GetPages(int pageIndex)
        {
            object objWhat = WdGoToItem.wdGoToPage;
            object objWhich = WdGoToDirection.wdGoToAbsolute;
            object oMissing = System.Reflection.Missing.Value;
            object objPage = pageIndex;
            Range range1 = wordDoc.GoTo(ref objWhat, ref objWhich, ref objPage, ref oMissing);
            Range range2 = range1.GoToNext(WdGoToItem.wdGoToPage);
            object objStart = range1.Start;
            object objEnd = range2.Start;
            if (range1.Start == range2.Start)
                objEnd = wordDoc.Characters.Count;
            return wordDoc.Range(ref objStart, ref objEnd);
        }


        public void DeletePage(int n, MSWord.Document wordDoc)
        {
            //删除指定页
            object oMissing = System.Reflection.Missing.Value;
            int pages = wordDoc.ComputeStatistics(WdStatistic.wdStatisticPages, ref oMissing);
            object objWhat = Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage;
            object objWhich = Microsoft.Office.Interop.Word.WdGoToDirection.wdGoToAbsolute;
            object objPage = n;//指定页  
            Microsoft.Office.Interop.Word.Range range1 = wordDoc.GoTo(ref objWhat, ref objWhich, ref objPage, ref oMissing);
            Microsoft.Office.Interop.Word.Range range2 = range1.GoToNext(Microsoft.Office.Interop.Word.WdGoToItem.wdGoToPage);
            object objStart = range1.Start;
            object objEnd = range2.Start;
            if (range1.Start == range2.Start)
                objEnd = wordDoc.Characters.Count;//最后一页  
            //string str1=wordDoc.Range(ref objStart, ref objEnd).Text;  
            //MessageBox.Show(str1);  
            //if (string.IsNullOrEmpty(str.Trim()))
            //{
            object Unit = (int)Microsoft.Office.Interop.Word.WdUnits.wdCharacter;
            object Count = 1;
            wordDoc.Range(ref objStart, ref  objEnd).Delete(ref  Unit, ref  Count);
            //}
            MessageBox.Show("删除成功");
        }
        /// <summary>
        /// 获取某目录下的所有文件(包括子目录下文件)的数量
        /// </summary>
        /// <param name="srcPath"></param>
        /// <returns></returns>
        public int GetFileNum(string srcPath)
        {
            int fileNum = 0;//文件的个数
            try
            {
                string[] fileList = System.IO.Directory.GetFileSystemEntries(srcPath);
                foreach (string file in fileList)
                {
                    if (System.IO.Directory.Exists(file))
                        GetFileNum(file);
                    else
                        fileNum++;
                }

            }
            catch (Exception e)
            {
                MessageBox.Show(e.ToString());
            }
            return fileNum;
        }
    }


}
